package likouJava;

public class jiekou {
//    1) 字符串拆分成数组，如”ab&&2”通过”&&”做分隔符，分割得到字符串数组[“ab”,”2”]

//
//            2) 实现字符串组合，如[“ab”,”2”]通过”&&”分隔符，组合成字符串”ab&&2”

//    public static void main(String[] args) {
////        int result = 0;
////        for (int i = 0; i < 1000; i++) {
////            if (i == i + 1){
////                result = i;
////            }else
////                i ++;
////        }
////        return result ;
////    }

    private static  int count = 0;

    private static final int Max = 200;

    public static final Object lock = new Object();

    public static  boolean isTtun = true;

    public static void main(String[] args) {
        Thread thread1 = new Thread(() -> {
            while (count <= Max){
                synchronized (lock){
                    while (!isTtun){
                        try {
                            lock.wait();
                        }catch (InterruptedException e){
                            Thread.currentThread().interrupt();
                            return;
                        }
                    }
                    if (count > Max){
                        break;
                    }
                    System.out.println("Thread1:" + count);
                    count ++;

                    isTtun = false;
                    lock.notify();
                }
            }
        },"Thread1");

        Thread thread2 = new Thread(() -> {
            while (count <= Max){
                synchronized (lock){
                    while (!isTtun){
                        try {
                            lock.wait();
                        }catch (InterruptedException e){
                            Thread.currentThread().interrupt();
                            return;
                        }
                    }
                    if (count > Max){
                        break;
                    }
                    System.out.println("Thread1:" + count);
                    count ++;

                    isTtun = true;
                    lock.notify();
                }
            }
        },"Thread2");
        thread1.start();
        thread2.start();
    }



}
